<!DOCTYPE html>
<html lang="zh-cn"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<head th:replace="common::head"></head>
<body>
<div th:replace="common::top"></div>
<br/>
<h2>编辑产品</h2>
<br/>
<form th:action="@{edit}" method="post" id="editForm">
    <ul style="text-align:left; margin-left:290px;">
        <li><span>ID:</span><span th:text="${product.id}"></span></li>
        <li><input type="text" name="name" th:value="${product.name}" required></li>
    </ul>
    <input type="number" name="id" th:value="${product.id}" hidden>
    <input type="submit" value="提交" style="width:220px;">
</form>
<p>
    <a href="javascript:history.back(-1);">返回上一页</a>
    <a href="../index.html" th:href="@{/index.html}">主页</a>
</p>

<script>
    $("#editForm").submit(function(e){
        e.preventDefault();

        $.ajax({
            type: $("#editForm").attr("method"),
            url: $("#editForm").attr("action"),
            data: $("#editForm").serialize(),
            success: function(response){
                alert("提交成功");
                window.location.href="list.html";
            },
            error: function(response){
                alert("提交失败");
            }
        });
    });
</script>

</body>
</html>